package com.ruoyi.web.controller.train;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.TrainingBaseMentorAll;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrainingBaseMentor;
import com.ruoyi.system.service.ITrainingBaseMentorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训导师信息Controller
 * 
 * @author dp
 * @date 2023-11-27
 */
@Api(tags={"培训导师信息"})
@RestController
@RequestMapping("/train/mentor")
public class TrainingBaseMentorController extends BaseController
{
    @Autowired
    private ITrainingBaseMentorService trainingBaseMentorService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询培训导师信息列表
     */
    @ApiOperation(value = "培训导师信息列表", notes = "查询培训导师信息列表详情", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingBaseMentor trainingBaseMentor)
    {
        startPage();
        List<TrainingBaseMentorAll> list = trainingBaseMentorService.selectTrainingBaseMentorList(trainingBaseMentor);
        return getDataTable(list);
    }

    /**
     * 导出培训导师信息列表
     */
    @ApiOperation(value = "培训导师信息列表导出", notes = "导出培训导师信息列表", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:export')")
    @Log(title = "培训导师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingBaseMentor trainingBaseMentor)
    {
        List<TrainingBaseMentorAll> list = trainingBaseMentorService.selectTrainingBaseMentorList(trainingBaseMentor);
        ExcelUtil<TrainingBaseMentorAll> util = new ExcelUtil<TrainingBaseMentorAll>(TrainingBaseMentorAll.class);
        util.exportExcel(response, list, "培训导师信息数据");
    }

    /**
     * 获取培训导师信息详细信息
     */
    @ApiOperation(value = "获取培训导师信息详细信息", notes = "获取培训导师信息详细信息详情", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:query')")
    @GetMapping(value = "/{mentorId}")
    public AjaxResult getInfo(@PathVariable("mentorId") Long mentorId)
    {
        return success(trainingBaseMentorService.selectTrainingBaseMentorByMentorId(mentorId));
    }

    /**
     * 新增培训导师信息
     */
    @ApiOperation(value = "新增培训导师信息", notes = "新增培训导师信息详情", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:add')")
    @Log(title = "培训导师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody TrainingBaseMentor trainingBaseMentor)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingBaseMentorService.completeData(trainingBaseMentor, userId, 1);
        return toAjax(trainingBaseMentorService.insertTrainingBaseMentor(trainingBaseMentor));
    }

    /**
     * 修改培训导师信息
     */
    @ApiOperation(value = "修改培训导师信息", notes = "修改培训导师信息详情", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:edit')")
    @Log(title = "培训导师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request, @RequestBody TrainingBaseMentor trainingBaseMentor)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingBaseMentorService.completeData(trainingBaseMentor, userId, 2);
        return toAjax(trainingBaseMentorService.updateTrainingBaseMentor(trainingBaseMentor));
    }

    /**
     * 删除培训导师信息
     */
    @ApiOperation(value = "删除培训导师信息", notes = "删除培训导师信息详情", tags = {"培训导师信息管理"})
    //@PreAuthorize("@ss.hasPermi('train:mentor:remove')")
    @Log(title = "培训导师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mentorIds}")
    public AjaxResult remove(@PathVariable Long[] mentorIds)
    {
        return toAjax(trainingBaseMentorService.deleteTrainingBaseMentorByMentorIds(mentorIds));
    }
}
